#include <guidesystem.h>

guideSystem::guideSystem(package *pkg)
{
    this->pkg = pkg;
    map = new myGraph(pkg);
}
guideSystem::~guideSystem()
{
    delete map;
}

void guideSystem::AddCurrentPoint(package* pkg)
{
    if(pkg->state.terminalPointFlag)
    {
        pkg->inP.startingPoint = this->pkg->inP.terminalPoint;
        pkg->inP.startingPointNum = map->string2Num(this->pkg->inP.terminalPoint);
    }
    else
    {
        pkg->inP.startingPoint = "当前位置";
        pkg->inP.startingPointNum = 0;
        map->point[0].pointCampus = pkg->inP.campus;
        map->point[0].pointName << "当前位置";
        map->point[0].pointType = 0;
        map->point[0].pointX = pkg->inP.currentLocationX;
        map->point[0].pointY = pkg->inP.currentLocationY;
        //在图中新增一个表示当前位置的点（编号为0），完善该点信息（名称，所在校区，类型，坐标）
        map->arc[0][pkg->inP.featherPointNum].distance = map->arc[pkg->inP.featherPointNum][pkg->inP.arrowPointNum].distance * pkg->inP.rateOfAdvance;
        map->arc[0][pkg->inP.featherPointNum].bikePass = map->arc[pkg->inP.featherPointNum][pkg->inP.arrowPointNum].bikePass;
        map->arc[0][pkg->inP.featherPointNum].congest = map->arc[pkg->inP.featherPointNum][pkg->inP.arrowPointNum].congest;
        map->arc[0][pkg->inP.arrowPointNum].distance = map->arc[pkg->inP.featherPointNum][pkg->inP.arrowPointNum].distance - map->arc[0][pkg->inP.featherPointNum].distance;
        map->arc[0][pkg->inP.arrowPointNum].bikePass = map->arc[pkg->inP.featherPointNum][pkg->inP.arrowPointNum].bikePass;
        map->arc[0][pkg->inP.arrowPointNum].congest = map->arc[pkg->inP.featherPointNum][pkg->inP.arrowPointNum].congest;
        //完善该点在图中的边信息，主要为与路段起（终）点构成新的路段并计算距离，此外，自行车通过性，拥挤度与原路段相同
    }
}

void guideSystem::findMatchingLocation(package* pkg)
{
    bool mcDebugFlag = false;

    delete map;
    map = new myGraph(this->pkg);

    int i,j;

    /**
     * @brief timeSpent         用于保存抵达某一周边地点的总用时
     */
    double timeSpent;

    /**
     * @brief distanceCross     用于保存抵达某一周边地点的总路程
     */
    double distanceCross;

    /**
     * @brief distance          用于保存当前点与图上某一点的距离，从而判断该点是否属于周边地点
     */
    double distance;

    /**
     * @brief tempkg            临时用于导航函数的数据包
     */
    package* tempkg = new package;
    tempkg->outP.matchingLocationNum.clear();
    tempkg->outP.matchingLocation.clear();
    tempkg->outP.matchingDistance.clear();
    tempkg->outP.matchingTimeSpent.clear();
    tempkg->outP.matchingNum = 0;
    for(int i = 0;i < 10;i++)
    {
        tempkg->outP.matchingRouteNum[i].clear();
        tempkg->outP.matchingRoute[i].clear();
        tempkg->outP.matchingSectionDistance[i].clear();
        tempkg->outP.matchingSectionTimeSpent[i].clear();
    }
    map->point[0].pointCampus = pkg->inP.campus;
    pkg->outP.matchingNum = 0;
    pkg->outP.matchingLocationNum.clear();
    pkg->outP.matchingLocation.clear();
    pkg->outP.matchingDistance.clear();
    pkg->outP.matchingTimeSpent.clear();
    for(i = 0;i<10;i++)
    {
        pkg->outP.matchingRouteNum[i].clear();
        pkg->outP.matchingRoute[i].clear();
        pkg->outP.matchingSectionDistance[i].clear();
        pkg->outP.matchingSectionTimeSpent[i].clear();
    }
    matchingInf.clear();

    AddCurrentPoint(pkg);

    int max = pkg->inP.campus ? map->pointBuildingNumXiTuCheng : map->pointBuildingNum.size();
    for(i = pkg->inP.campus ? 0 : map->pointBuildingNumXiTuCheng; i < max; i++)
    {
        matching tempMatching;
        //判断地点与使用者的距离是否小于一公里,以及该地点是否为服务地点
//        distance = (pkg->inP.currentLocationX - map->point[i].pointX)*(pkg->inP.currentLocationX - map->point[i].pointX) + (pkg->inP.currentLocationY - map->point[i].pointY)*(pkg->inP.currentLocationY - map->point[i].pointY);
        pkg->state.scale = pkg->inP.campus ? pkg->state.scaleShaHe : pkg->state.scaleXiTuCheng;
        distance = qSqrt(qPow(pkg->inP.currentLocationX - map->point[map->pointBuildingNum[i]].pointX, 2) +
                         qPow(pkg->inP.currentLocationY - map->point[map->pointBuildingNum[i]].pointY, 2))
                * pkg->state.scale;
        if(distance < 300)
        {
           timeSpent = 0.0;
           distanceCross = 0.0;
           //确认地点为周边地点后，清零总耗时和总路程以备之后的计算
           tempkg->inP.terminalPoint = map->num2String(map->pointBuildingNum[i]);
           tempkg->inP.terminalPointNum = map->pointBuildingNum[i];
           if(pkg->state.terminalPointFlag)
           {
               tempkg->inP.startingPoint = pkg->inP.terminalPoint;
               tempkg->inP.startingPointNum = map->string2Num(pkg->inP.terminalPoint);
           }
           else
           {
               tempkg->inP.startingPoint = "当前位置";
               tempkg->inP.startingPointNum = 0;
           }
           if(tempkg->inP.startingPointNum == tempkg->inP.terminalPointNum)
               continue;
           tempkg->inP.strategy = 1;
           tempkg->inP.vehicle = pkg->inP.vehicle;
           tempkg->myClock.time = pkg->myClock.time;
           //构建临时输入包，起点为当前位置，终点为周边地点，执行时间最短策略，交通方式与当前导航相同
           if(mcDebugFlag)
           {
               qDebug() << "findMatchingLocation" << ++debugNum << "terminalPoint:" << "\n" <<
                           tempkg->inP.terminalPoint;
           }
           findNavigationRoute(tempkg);
           if(mcDebugFlag)
           {
               qDebug() << "findMatchingLocation" << ++debugNum << "tempkg->outP.navigationRoute:" << "\n" <<
                           tempkg->outP.navigationRoute;
           }
//                   pkg->outP.matchingRouteNum[pkg->outP.matchingNum] << tempkg->outP.navigationRouteNum[0];
           tempMatching.matchingRouteNum << tempkg->outP.navigationRouteNum[0];
//                   pkg->outP.matchingRoute[pkg->outP.matchingNum] << tempkg->outP.navigationRoute[0];
           tempMatching.matchingRoute << tempkg->outP.navigationRoute[0];
           for(j = 0; j < tempkg->outP.navigationTimeSpent.size(); j++){
               timeSpent += tempkg->outP.navigationTimeSpent[j];
               distanceCross += tempkg->outP.navigationDistance[j];
//                       pkg->outP.matchingRouteNum[pkg->outP.matchingNum] << tempkg->outP.navigationRouteNum[j + 1];
               tempMatching.matchingRouteNum << tempkg->outP.navigationRouteNum[j + 1];
//                       pkg->outP.matchingRoute[pkg->outP.matchingNum] << tempkg->outP.navigationRoute[j + 1];
               tempMatching.matchingRoute << tempkg->outP.navigationRoute[j + 1];
//                       pkg->outP.matchingSectionDistance[pkg->outP.matchingNum] << tempkg->outP.navigationDistance[j];
               tempMatching.matchingSectionDistance << tempkg->outP.navigationDistance[j];
//                       pkg->outP.matchingSectionTimeSpent[pkg->outP.matchingNum] << tempkg->outP.navigationTimeSpent[j];
               tempMatching.matchingSectionTimeSpent  << tempkg->outP.navigationTimeSpent[j];
           }
           if(mcDebugFlag)
           {
               qDebug() << "findMatchingLocation" << ++debugNum << "tempMatching.matchingRoute:" << "\n" <<
                           tempMatching.matchingRoute;
           }
//                   pkg->outP.matchingTimeSpent << timeSpent;
           tempMatching.matchingTimeSpent = timeSpent;
//                   pkg->outP.matchingDistance << distanceCross;
           tempMatching.matchingDistance = distanceCross;
//                   pkg->outP.matchingLocationNum << i;
           tempMatching.matchingLocationNum = i;
//                   pkg->outP.matchingLocation << map->point[i].pointName[0];
           tempMatching.matchingLocation = map->point[map->pointBuildingNum[i]].pointName[0];
           matchingInf << tempMatching;
           //根据导航函数运行结果，保存导航信息（途径点名称，各段路程及耗时）并计算总路程和总耗时
        }
    }

    //排序
    int num;
    double min;
    for(i = 0; i < 10 && i < matchingInf.size(); i++)
    {
        num = 0;
        min = matchingInf[0].matchingDistance;
        for(j = 0; j < matchingInf.size(); j++)
        {
            if(matchingInf[j].matchingDistance < min)
            {
                num = j;
                min = matchingInf[j].matchingDistance;
            }
        }
        //录入
//        pkg->outP.matchingRouteNum[pkg->outP.matchingNum] << tempkg->outP.navigationRouteNum[0];
        pkg->outP.matchingRouteNum[pkg->outP.matchingNum] << matchingInf[num].matchingRouteNum[0];
//        pkg->outP.matchingRoute[pkg->outP.matchingNum] << tempkg->outP.navigationRoute[0];
        pkg->outP.matchingRoute[pkg->outP.matchingNum] << matchingInf[num].matchingRoute[0];
//        for(j = 0; j < tempkg->outP.navigationTimeSpent.size(); j++){
        for(j = 0; j < matchingInf[num].matchingSectionTimeSpent.size(); j++)
        {
//            pkg->outP.matchingRouteNum[pkg->outP.matchingNum] << tempkg->outP.navigationRouteNum[j + 1];
            pkg->outP.matchingRouteNum[pkg->outP.matchingNum] << matchingInf[num].matchingRouteNum[j + 1];
//            pkg->outP.matchingRoute[pkg->outP.matchingNum] << tempkg->outP.navigationRoute[j + 1];
            pkg->outP.matchingRoute[pkg->outP.matchingNum] << matchingInf[num].matchingRoute[j + 1];
//            pkg->outP.matchingSectionDistance[pkg->outP.matchingNum] << tempkg->outP.navigationDistance[j];
            pkg->outP.matchingSectionDistance[pkg->outP.matchingNum] << matchingInf[num].matchingSectionDistance[j];
//            pkg->outP.matchingSectionTimeSpent[pkg->outP.matchingNum] << tempkg->outP.navigationTimeSpent[j];
            pkg->outP.matchingSectionTimeSpent[pkg->outP.matchingNum] << matchingInf[num].matchingSectionTimeSpent[j];
        }
        if(mcDebugFlag)
        {
            qDebug() << "findMatchingLocation" << ++debugNum << "matchingRoute:" << "\n" <<
                        pkg->outP.matchingRoute[pkg->outP.matchingNum];
        }
        pkg->outP.matchingNum++;
        pkg->outP.matchingTimeSpent << matchingInf[num].matchingTimeSpent;
        pkg->outP.matchingDistance << matchingInf[num].matchingDistance;
        pkg->outP.matchingLocationNum << matchingInf[num].matchingLocationNum;
        pkg->outP.matchingLocation << matchingInf[num].matchingLocation;
        matchingInf.removeAt(num);
    }

//    pkg->outP.matchingRouteNum[pkg->outP.matchingNum] << tempkg->outP.navigationRouteNum[0];
//    pkg->outP.matchingRoute[pkg->outP.matchingNum] << tempkg->outP.navigationRoute[0];
//    for(j = 0; j < tempkg->outP.navigationTimeSpent.size(); j++){
//        timeSpent += tempkg->outP.navigationTimeSpent[j];
//        distanceCross += tempkg->outP.navigationDistance[j];
//        pkg->outP.matchingRouteNum[pkg->outP.matchingNum] << tempkg->outP.navigationRouteNum[j + 1];
//        pkg->outP.matchingRoute[pkg->outP.matchingNum] << tempkg->outP.navigationRoute[j + 1];
//        pkg->outP.matchingSectionDistance[pkg->outP.matchingNum] << tempkg->outP.navigationDistance[j];
//        pkg->outP.matchingSectionTimeSpent[pkg->outP.matchingNum] << tempkg->outP.navigationTimeSpent[j];
//    }
//    pkg->outP.matchingNum++;
//    pkg->outP.matchingTimeSpent << timeSpent;
//    pkg->outP.matchingDistance << distanceCross;
//    pkg->outP.matchingLocationNum << i;
//    pkg->outP.matchingLocation << map->point[i].pointName;
//    //根据导航函数运行结果，保存导航信息（途径点名称，各段路程及耗时）并计算总路程和总耗时

    map->point[0].pointCampus = 0;
    map->point[0].pointName.clear();
    map->point[0].pointType = 0;
    map->point[0].pointX = -1;
    map->point[0].pointY = -1;
    for(j = 0; j < map->pointNum; j++)
    {
        map->arc[0][j].prePoint.clear();
        map->arc[0][j].prePoint << j;
        map->arc[0][j].bikePass = false;
        map->arc[0][j].congest = 1;
        map->arc[0][j].distance = infinite;
    }
    //在查找到足够数量的周边点后（待做），还原0点信息至默认状态，准备迎接下一次使用
    delete tempkg;
}

void guideSystem::findNavigationRoute(package* pkg)
{
    map->Init();

    int i,j,k,m,n;

    /**
     * @brief viaFeatherPoint_Num   必经点[i]在默认点集中对应的序号
     */
    int viaFeatherPoint_Num;

    /**
     * @brief viaArrowPoint_Num     必经点[i+1]在默认点集对应的序号
     */
    int viaArrowPoint_Num;

    /**
     * @brief haveFound     在算法中判断一个点是否曾被列为最小值
     */
    bool haveFound[map->pointNum];

    /**
     * @brief beeline       在算法中用于保存当前起点与其他（未查找过的）点的最小距离
     */
    double beeline;

    /**
     * @brief nearestPoint  在算法中用于保存当前距起点最近的（未查找过的）点在列表中的编号
     */
    int nearestPoint;

    if(pkg->inP.strategy != 2)
    {
        pkg->outP.navigationRouteNum.clear();
        pkg->outP.navigationRoute.clear();
        pkg->outP.navigationDistance.clear();
        pkg->outP.navigationTimeSpent.clear();
    }

    for(i = 0; i < map->pointNum; i++)
    {
        if(map->point[i].pointType == 0)
            haveFound[i] = false;
        else
            haveFound[i] = true;
    }
    //对表格初始化，默认所有点都未曾被列入最小值

    switch (pkg->inP.strategy)
    {
    case 0 :
    //距离最短（寻找起点到终点的最短路径，不考虑拥挤度）
        pkg->inP.startingPointNum = map->string2Num(pkg->inP.startingPoint);
        pkg->inP.terminalPointNum = map->string2Num(pkg->inP.terminalPoint);
                for(i=0;i<map->pointNum;i++)
                {
                    beeline = infinite;
                    nearestPoint = pkg->inP.startingPointNum;
                    //设置起点与其他点的最小距离为无穷，默认最近点为起点本身
                    for(j=1;j<=map->pointNum;j++)
                    {
                        if(pkg->inP.vehicle == 1 )
                        {

                            if(map->arc[pkg->inP.startingPointNum][j].bikePass == true && haveFound[j] == false && map->arc[pkg->inP.startingPointNum][j].distance < beeline)
                            {
                                beeline = map->arc[pkg->inP.startingPointNum][j].distance;
                                nearestPoint = j;
                            }
                        }
                        else
                        {
                            if(haveFound[j] == false && map->arc[pkg->inP.startingPointNum][j].distance < beeline)
                            {
                                beeline = map->arc[pkg->inP.startingPointNum][j].distance;
                                nearestPoint = j;
                            }
                        }
                    }
                    haveFound[nearestPoint] = true;
                    //在图中所有点中查找距离起点最近的点，记录该点以及最小距离（if情形针对骑行增加自行车能否通过的判断），标记其为已查找
                    for(k=1;k<=map->pointNum;k++)
                    {
                        if(pkg->inP.vehicle == 1)
                        {
                            if(map->arc[nearestPoint][k].bikePass == true)
                            {
                                if(map->arc[pkg->inP.startingPointNum][k].distance > (map->arc[pkg->inP.startingPointNum][nearestPoint].distance + map->arc[nearestPoint][k].distance))
                                {
                                    map->arc[pkg->inP.startingPointNum][k].distance = (map->arc[pkg->inP.startingPointNum][nearestPoint].distance + map->arc[nearestPoint][k].distance);
                                    map->arc[pkg->inP.startingPointNum][k].bikePass = true;
                                    map->arc[pkg->inP.startingPointNum][k].prePoint = map->arc[pkg->inP.startingPointNum][nearestPoint].prePoint;
                                    map->arc[pkg->inP.startingPointNum][k].prePoint << k;
                                }
                            }
                        }
                        else
                        {
                            if(map->arc[pkg->inP.startingPointNum][k].distance > (map->arc[pkg->inP.startingPointNum][nearestPoint].distance + map->arc[nearestPoint][k].distance))
                            {
                                map->arc[pkg->inP.startingPointNum][k].distance = (map->arc[pkg->inP.startingPointNum][nearestPoint].distance + map->arc[nearestPoint][k].distance);
                                map->arc[pkg->inP.startingPointNum][k].prePoint = map->arc[pkg->inP.startingPointNum][nearestPoint].prePoint;
                                map->arc[pkg->inP.startingPointNum][k].prePoint << k;
                            }
                        }
                    }
                    //以该点为中继结点，观察起点到其他点的距离是否可以缩短
                    //若可以缩短，则在边中增加相应的中继结点，修改起点到该点的距离（if情形针对骑行增加自行车能否通过的判断）
                    //随后重复以上过程，直至校区内所有点都被标记已查找（待做）
                }
                //如果起点与终点之间有可达路径，存储导航路线及其对应各段的距离，耗时等信息
                if(map->arc[pkg->inP.startingPointNum][pkg->inP.terminalPointNum].distance < infinite)
                {
                    m = pkg->inP.startingPointNum;
                    if(pkg->inP.strategy != 2)
                    {
                        pkg->outP.navigationRouteNum << map->string2Num(pkg->inP.startingPoint);
                        pkg->outP.navigationRoute << pkg->inP.startingPoint;
                    }
                    //保存第一个途径点（起点），作为路段起点
                    for(i=0;i<map->arc[pkg->inP.startingPointNum][pkg->inP.terminalPointNum].prePoint.size();i++)
                    {
                        n = map->arc[pkg->inP.startingPointNum][pkg->inP.terminalPointNum].prePoint[i];
                        pkg->outP.navigationRouteNum << n;
                        pkg->outP.navigationRoute << map->num2String(n);
                        pkg->outP.navigationDistance << map->arc[m][n].distance;
                        //保存下一个途径点，作为路段终点，计算并保存路段的长度
                        if(pkg->inP.vehicle == 1)
                        {
                            pkg->outP.navigationTimeSpent << (map->arc[m][n].distance / bikeSpeed);
                            //计算并保存路段的（骑行）耗时
                        }
                        else
                        {
                            pkg->outP.navigationTimeSpent << (map->arc[m][n].distance / walkSpeed);
                            //计算并保存路段的（步行）耗时
                        }
                        m = n;
                        //将当前路段的终点作为下一路段的起点，重复以上过程，直至抵达终点
                    }
                }
        break;
    case 2 :
    //包含必经点（寻找起点到必经点/终点的最短路径，不考虑拥挤度）
        viaFeatherPoint_Num = map->string2Num(pkg->inP.viaPoint[pkg->inP.viaNum]);
        viaArrowPoint_Num = map->string2Num(pkg->inP.viaPoint[pkg->inP.viaNum+1]);
                for(i=0;i<map->pointNum;i++)
                {
                    beeline = infinite;
                    nearestPoint = viaFeatherPoint_Num;
                    //设置起点与其他点的最小距离为无穷，默认最近点为起点本身
                    for(j=1;j<=map->pointNum;j++)
                    {
                        if(pkg->inP.vehicle == 1 )
                        {

                            if(map->arc[viaFeatherPoint_Num][j].bikePass == true && haveFound[j] == false && map->arc[viaFeatherPoint_Num][j].distance < beeline)
                            {
                                beeline = map->arc[viaFeatherPoint_Num][j].distance;
                                nearestPoint = j;
                            }
                        }
                        else
                        {
                            if(haveFound[j] == false && map->arc[viaFeatherPoint_Num][j].distance < beeline)
                            {
                                beeline = map->arc[viaFeatherPoint_Num][j].distance;
                                nearestPoint = j;
                            }
                        }
                    }
                    haveFound[nearestPoint] = true;
                    //在图中所有点中查找距离起点最近的点，记录该点以及最小距离（if情形针对骑行增加自行车能否通过的判断），标记其为已查找
                    for(k=1;k<=map->pointNum;k++)
                    {
                        if(pkg->inP.vehicle == 1)
                        {
                            if(map->arc[nearestPoint][k].bikePass == true)
                            {
                                if(map->arc[viaFeatherPoint_Num][k].distance > (map->arc[viaFeatherPoint_Num][nearestPoint].distance + map->arc[nearestPoint][k].distance))
                                {
                                    map->arc[viaFeatherPoint_Num][k].distance = (map->arc[viaFeatherPoint_Num][nearestPoint].distance + map->arc[nearestPoint][k].distance);
                                    map->arc[viaFeatherPoint_Num][k].bikePass = true;
                                    map->arc[viaFeatherPoint_Num][k].prePoint = map->arc[viaFeatherPoint_Num][nearestPoint].prePoint;
                                    map->arc[viaFeatherPoint_Num][k].prePoint << k;
                                }
                            }
                        }
                        else
                        {
                            if(map->arc[viaFeatherPoint_Num][k].distance > (map->arc[viaFeatherPoint_Num][nearestPoint].distance + map->arc[nearestPoint][k].distance))
                            {
                                map->arc[viaFeatherPoint_Num][k].distance = (map->arc[viaFeatherPoint_Num][nearestPoint].distance + map->arc[nearestPoint][k].distance);
                                map->arc[viaFeatherPoint_Num][k].prePoint = map->arc[viaFeatherPoint_Num][nearestPoint].prePoint;
                                map->arc[viaFeatherPoint_Num][k].prePoint << k;
                            }
                        }
                    }
                    //以该点为中继结点，观察起点到其他点的距离是否可以缩短
                    //若可以缩短，则在边中增加相应的中继结点，修改起点到该点的距离（if情形针对骑行增加自行车能否通过的判断）
                    //随后重复以上过程，直至校区内所有点都被标记已查找（待做）
                }
                //如果起点与终点之间有可达路径，存储导航路线及其对应各段的距离，耗时等信息
                if(map->arc[viaFeatherPoint_Num][viaArrowPoint_Num].distance < infinite)
                {
                    m = viaFeatherPoint_Num;
                    if(pkg->inP.viaNum == 0)
                    {
                        pkg->outP.navigationRouteNum << map->string2Num(pkg->inP.startingPoint);
                        pkg->outP.navigationRoute << pkg->inP.startingPoint;
                    }
                    //保存第一个途径点（起点），作为路段起点
                    for(i=0;i<map->arc[viaFeatherPoint_Num][viaArrowPoint_Num].prePoint.size();i++)
                    {
                        n = map->arc[viaFeatherPoint_Num][viaArrowPoint_Num].prePoint[i];
                        pkg->outP.navigationRouteNum << n;
                        pkg->outP.navigationRoute << map->num2String(n);
                        pkg->outP.navigationDistance << map->arc[m][n].distance;
                        //保存下一个途径点，作为路段终点，计算并保存路段的长度
                        if(pkg->inP.vehicle == 1)
                        {
                            pkg->outP.navigationTimeSpent << (map->arc[m][n].distance / bikeSpeed);
                            //计算并保存路段的（骑行）耗时
                        }
                        else
                        {
                            pkg->outP.navigationTimeSpent << (map->arc[m][n].distance / walkSpeed);
                            //计算并保存路段的（步行）耗时
                        }
                        m = n;
                        //将当前路段的终点作为下一路段的起点，重复以上过程，直至抵达终点
                    }
                }
        break;
    //耗时最少（以最快抵达终点为目标，需考虑当前时刻各路段的拥挤度）
    case 1 :
        pkg->inP.startingPointNum = map->string2Num(pkg->inP.startingPoint);
        pkg->inP.terminalPointNum = map->string2Num(pkg->inP.terminalPoint);
        for(i=0;i<map->pointNum;i++)
        {
            beeline = infinite;
            nearestPoint = pkg->inP.startingPointNum;
            //设置起点与其他点的最小距离为无穷，默认最近点为起点本身
            for(j=1;j<=map->pointNum;j++)
            {
                if(pkg->inP.vehicle == 1)
                {
                    if(map->arc[pkg->inP.startingPointNum][j].bikePass == true && haveFound[j] == false && (map->arc[pkg->inP.startingPointNum][j].distance * map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, j)) < beeline)
                    {
                        beeline = (map->arc[pkg->inP.startingPointNum][j].distance * map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, j));

                        nearestPoint = j;
                    }
                }
                else
                {
                    if(haveFound[j] == false && (map->arc[pkg->inP.startingPointNum][j].distance * map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, j)) < beeline)
                    {
                        beeline = (map->arc[pkg->inP.startingPointNum][j].distance * map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, j));
                        nearestPoint = j;
                    }
                }
            }
            haveFound[nearestPoint] = true;
            //在图中查找可以最快到达的点，记录该点以及最小等价距离（等价距离 = 距离 * 拥挤度），标记其为已查找（if情形针对骑行增加自行车能否通过的判断）
            for(k=1;k<=map->pointNum;k++)
            {
                if(pkg->inP.vehicle == 1)
                {
                    if(map->arc[nearestPoint][k].bikePass == true)
                    {
                        if((map->arc[pkg->inP.startingPointNum][k].distance * map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, k)) > (map->arc[pkg->inP.startingPointNum][nearestPoint].distance * map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, nearestPoint) + map->arc[nearestPoint][k].distance * map->CalculateCongestion(pkg->myClock.time, nearestPoint, k)))
                        {
                            map->arc[pkg->inP.startingPointNum][k].distance = (map->arc[pkg->inP.startingPointNum][nearestPoint].distance * map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, nearestPoint) + map->arc[nearestPoint][k].distance * map->CalculateCongestion(pkg->myClock.time, nearestPoint, k)) / map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, k);
                            map->arc[pkg->inP.startingPointNum][k].bikePass = true;
                            map->arc[pkg->inP.startingPointNum][k].prePoint = map->arc[pkg->inP.startingPointNum][nearestPoint].prePoint;
                            map->arc[pkg->inP.startingPointNum][k].prePoint << k;
                        }
                    }
                }
                else
                {
                    if(map->arc[pkg->inP.startingPointNum][k].distance * map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, k) > (map->arc[pkg->inP.startingPointNum][nearestPoint].distance * map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, nearestPoint) + map->arc[nearestPoint][k].distance * map->CalculateCongestion(pkg->myClock.time, nearestPoint, k)))
                    {
                        map->arc[pkg->inP.startingPointNum][k].distance = (map->arc[pkg->inP.startingPointNum][nearestPoint].distance * map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, nearestPoint) + map->arc[nearestPoint][k].distance * map->CalculateCongestion(pkg->myClock.time, nearestPoint, k)) / map->CalculateCongestion(pkg->myClock.time, pkg->inP.startingPointNum, k);
                        map->arc[pkg->inP.startingPointNum][k].prePoint = map->arc[pkg->inP.startingPointNum][nearestPoint].prePoint;
                        map->arc[pkg->inP.startingPointNum][k].prePoint << k;
                    }
                }
            }
            //以该点为中继结点，观察起点到其他点的等价距离（等价距离 = 距离 * 拥挤度）是否可以缩短
            //若可以缩短，则在边中增加相应的中继结点，修改起点到该点的等价距离（if情形针对骑行增加自行车能否通过的判断）
            //随后重复以上过程，直至校区内所有点都被标记已查找（待做）
        }
        //如果起点与终点之间有可达路径，存储导航路线及其对应各段的距离，耗时等信息
        if(map->arc[pkg->inP.startingPointNum][pkg->inP.terminalPointNum].distance < infinite)
        {
            m = pkg->inP.startingPointNum;
            pkg->outP.navigationRouteNum << map->string2Num(pkg->inP.startingPoint);
            pkg->outP.navigationRoute << pkg->inP.startingPoint;
            //保存第一个途径点（起点），作为路段起点
            for(i=0;i<map->arc[pkg->inP.startingPointNum][pkg->inP.terminalPointNum].prePoint.size();i++)
            {
                n = map->arc[pkg->inP.startingPointNum][pkg->inP.terminalPointNum].prePoint[i];
                pkg->outP.navigationRouteNum << n;
                pkg->outP.navigationRoute << map->num2String(n);
                pkg->outP.navigationDistance << map->arc[m][n].distance;
                //保存下一个途径点，作为路段终点，计算并保存路段的长度
                if(pkg->inP.vehicle == 1)
                {
                    pkg->outP.navigationTimeSpent << (map->arc[m][n].distance * map->CalculateCongestion(pkg->myClock.time, m, n) / bikeSpeed);
                    //计算并保存路段的（骑行）耗时
                }
                else
                {
                    pkg->outP.navigationTimeSpent << (map->arc[m][n].distance * map->CalculateCongestion(pkg->myClock.time, m, n) / walkSpeed);
                   //计算并保存路段的（步行）耗时
                }
                m = n;
                //将当前路段的终点作为下一路段的起点，重复以上过程，直至抵达终点
            }
        }
                break;
    default:
             qDebug() << "程序出现错误，请检查输入数据包中的策略编号是否正确";
                break;
    }
}
